﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DCSLibrary;
using System.Data;
using System.Collections;
using Utils.DC.Web.UI;
using Telerik.Web.UI;
using Utils;

public partial class quan_tri_trang_chuc_nang : System.Web.UI.UserControl
{
    FunctionPageUI objFunctionPage = new FunctionPageUI();
    DataSet dsFunctionPage = new DataSet();
    MessageBox messageBox;

    #region Cac Ham Su Kien

    protected void Page_Load(object sender, EventArgs e)
    {
        

        if (!IsPostBack)
        {
            BindFunctionPage();
        }
    }

    protected void FunctionPage_Delete(object source, GridCommandEventArgs e)
    {
        try
        {
            int id = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.Items[e.Item.ItemIndex]["FunctionPageID"].Text.ToString());
            int result = objFunctionPage.DeleteByID(id);
            if (result > 0)
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_SUCCESSFULLY;
                BindFunctionPage();
            }
            else
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_NOT_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_NOT_SUCCESSFULLY;
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = MessageBox.MESSAGE_CONFILCT_DATA;
            BindFunctionPage();
        }
    }

    protected void FunctionPage_Edit(object sender, EventArgs e)
    {
        //LinkButton button = (LinkButton)sender;
        //int id = Convert.ToInt32(button.CommandArgument);
        //LoadEditData(id);
    }

    private void BindFunctionPage()
    {
        dsFunctionPage = objFunctionPage.GetTop();
        grdFunctionPage.DataSource = dsFunctionPage.Tables[0];
        grdFunctionPage.DataBind();
    }

    protected void Ajax_Request(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            dsFunctionPage = objFunctionPage.GetAll();
            BindFunctionPage();
        }
    }

    protected void grd_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        BindFunctionPage();
    }
    protected void lbt_Click(object sender, EventArgs e)
    {
        try
        {
            LinkButton lbt = (LinkButton)sender;
            int result = Convert.ToInt32(lbt.CommandArgument);
            Response.Redirect("/Admin/Form/FunctionPage_Add.aspx?id=" + result);
        }
        catch (Exception)
        {

            throw;
        }
    }
    #endregion
}
